/*******************************************************************************
 * Copyright (c) 2011 squid.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     squid - initial API and implementation
 ******************************************************************************/
package com.google.code.cubeirc.sdk;

import java.io.File;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.apache.log4j.Level;

import com.google.code.cubeirc.common.ApplicationInfo;
import com.google.code.cubeirc.debug.DebuggerQueue;

import lombok.Getter;
import lombok.Setter;

public final class CubePluginsHost {

	@Setter @Getter
	private static ConcurrentLinkedQueue<ICubePlugin> plugins = new ConcurrentLinkedQueue<ICubePlugin>();


	/**
	 * Add plugin to plugins host and initialized
	 * @param plugin
	 * @return
	 */
	public static boolean addPlugin(ICubePlugin plugin)
	{
		try
		{
			getPlugins().add(plugin);
			plugin.init(null);
			return true;
		}
		catch(Exception ex)
		{
			DebuggerQueue.addDebug("CubePluginsHost", Level.FATAL, "Error during load plugin: %s error:%s", plugin.getName(), ex.getMessage());
			return false;
		}	
	}

	public static void initPlugins(String folder)
	{
		if (folder.isEmpty() || folder == null)
			folder = ApplicationInfo.PLG_DEFAULT_DIRECTORY;

		File plg_dir = new File(folder);

		if (plg_dir.exists())
		{
			

		}
		else
		{
			plg_dir.mkdir();
			DebuggerQueue.addDebug("CubePluginsHost", Level.WARN, "%s is empty of not created! So I can't load plugins!",folder);
		}

	}


}
